<template>
	<div class="sw_file_preview">
		<video-preview v-model="videoToggle" :src="fileUrl" @close="handleCloseView"></video-preview>
		<elImageViewer v-if="imageToggle" :url-list="imageList" :on-close="handleCloseView"></elImageViewer>
		<document-preview v-model="documentToggle" :src="fileUrl" @close="handleCloseView"></document-preview>
	</div>
</template>

<script>
import videoPreview from './video';
import documentPreview from './document';
import elImageViewer from 'element-ui/packages/image/src/image-viewer';
export default {
	components: { videoPreview, documentPreview, elImageViewer },
	data() {
		return {
			fileUrl: '',
			imageList: [],
			videoToggle: false,
			imageToggle: false,
			documentToggle: false
		};
	},
	mounted() {
		this.$bus.$on('filePreview', (data, type) => {
			this.previewToggle = true;
			if (type === 'document') {
				let baseUrl = process.env.VUE_APP_BASEURL;
				this.fileUrl = `${baseUrl}/openApi/office/office2pdf/${data.fileId}`;
				this.documentToggle = true;
			} else if (type === 'image') {
				let httpUrl = data?.sysAttachment?.httpUrl;
				this.imageList = !httpUrl ? [] : [httpUrl.replaceIP()];
				this.imageToggle = true;
			} else if (type === 'video') {
				let httpUrl = data?.sysAttachment?.httpUrl;
				this.fileUrl = !httpUrl ? '' : httpUrl.replaceIP();
				this.videoToggle = true;
			} else if (type === 'audio') {
				console.log('123123');
			} else {
				console.log('123123');
			}
		});
	},
	destroyed() {
		this.$bus.$off('filePreview');
	},
	methods: {
		handleCloseView() {
			this.documentToggle = false;
			this.imageToggle = false;
			this.videoToggle = false;
			this.fileUrl = '';
		}
	}
};
</script>

<style lang="scss" scoped></style>
